﻿ <!-- Copyright (c) 2016, Dijji, and released under Ms-PL.  This can be found in the root of this distribution.-->
 <Window x:Class="XstReader.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Xst Reader" Height="800" Width="1500">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="VisibleIfTrue"/>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="3"/>
            <ColumnDefinition Width="5*"/>
            <ColumnDefinition Width="3"/>
            <ColumnDefinition Width="7*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="30"/>
            </Grid.RowDefinitions>
            <TreeView Grid.Row="0" Name="treeFolders" ItemsSource="{Binding Path=RootFolders}" FontSize="12" SelectedItemChanged="treeFolders_SelectedItemChanged">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Path=Folders}">
                        <Grid>
                            <TextBlock Text="{Binding Path=Description}" />
                        </Grid>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <TreeView.ItemContainerStyle>
                    <Style>
                        <Setter Property="TreeViewItem.IsExpanded" Value="true"/>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
            <StackPanel Grid.Row="2" Orientation="Horizontal">
                <Button Content="Open..." Height="20" HorizontalAlignment="Left" Margin="10,5,0,0" Name="btnOpen" VerticalAlignment="Top" Width="75" Click="btnOpen_Click" />
                <TextBlock Name="txtStatus" Margin="20,7,0,0" Width="100" />
            </StackPanel>
        </Grid>
        <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Stretch" />
        <Grid Grid.Column="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="30"/>
            </Grid.RowDefinitions>
            <ListView Grid.Row="0"  Name="listMessages" Margin="0,0,0,0" DataContext="{Binding Path=SelectedFolder}" ItemsSource="{Binding Path=Messages}"
                      SelectionChanged="listMessages_SelectionChanged" FontSize="12">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="15" >
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Tag="HasAttachment" Click="listMessagesColumnHeader_Click">A</GridViewColumnHeader>
                            </GridViewColumn.Header>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <!--use the Unicode paperclip character to mark messages with attachments-->
                                    <TextBlock Text=" &#x1f4ce;" Margin="-8,0,0,0" Visibility="{Binding HasAttachment, Converter={StaticResource VisibleIfTrue}}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="350" >
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Tag="Subject" Click="listMessagesColumnHeader_Click">Subject</GridViewColumnHeader>
                            </GridViewColumn.Header>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Subject}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="100" >
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Tag="FromTo" Click="listMessagesColumnHeader_Click">From or To</GridViewColumnHeader>
                            </GridViewColumn.Header>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=FromTo}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="120">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Tag="Date" Click="listMessagesColumnHeader_Click">Date</GridViewColumnHeader>
                            </GridViewColumn.Header>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=DisplayDate}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
        <GridSplitter Grid.Column="3" Width="3" HorizontalAlignment="Stretch" />
        <Grid Grid.Column="4">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="30"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0" Visibility="{Binding ShowContent, Converter={StaticResource VisibleIfTrue}}">
                <TextBox  DataContext="{Binding Path=CurrentMessage}" Text="{Binding Path=Body}"
                     Visibility="{Binding ShowText, Converter={StaticResource VisibleIfTrue}}"/>
                <WebBrowser Name="wbMessage" DataContext="{Binding Path=CurrentMessage}" 
                     Visibility="{Binding ShowHtml, Converter={StaticResource VisibleIfTrue}}"/>
                <RichTextBox Name="rtfMessage" DataContext="{Binding Path=CurrentMessage}" 
                     Visibility="{Binding ShowRtf, Converter={StaticResource VisibleIfTrue}}"/>
            </Grid>
            <Grid Grid.Row="0" Visibility="{Binding ShowProperties, Converter={StaticResource VisibleIfTrue}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="3"/>
                    <RowDefinition Height="4*"/>
                </Grid.RowDefinitions>
                <ListView Grid.Row="0"  Name="listRecipients" Margin="0,0,0,0" ItemsSource="{Binding Path=CurrentMessage.Recipients}" 
                      SelectionChanged="listRecipients_SelectionChanged" FontSize="12">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="100" Header="Type" >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=RecipientType}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="200" Header="Name"  >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=DisplayName}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="400" Header="Email"  >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=EmailAddress}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
                <GridSplitter Grid.Row="1" Height="3" HorizontalAlignment="Stretch" />
                <ListView Grid.Row="2"  Name="listProperties" Margin="0,0,0,0" ItemsSource="{Binding Path=CurrentProperties}" FontSize="12">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="50" Header="Id" >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=DisplayId}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="200" Header="Description"  >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=Description}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="400" Header="Value"  >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=DisplayValue}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
            <ListView Grid.Row="1"  Name="listAttachments" Margin="0,0,0,0" ItemsSource="{Binding Path=CurrentMessage.Attachments}" MaxHeight="200"
                      SelectionChanged="listAttachments_SelectionChanged" FontSize="12" Visibility="{Binding IsAttachmentPresent, Converter={StaticResource VisibleIfTrue}}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="75" Header="Type"  >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Type}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="300" Header="Attachment" >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Description}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="50" Header="Size"  >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Size}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                      </GridView>
                </ListView.View>
            </ListView>
            <StackPanel Grid.Row="2" Orientation="Horizontal">
                <Button Content="Save File..." Height="20" Margin="10,5,0,0" Name="btnSave" VerticalAlignment="Top" Width="75" Click="btnSave_Click"
                        Visibility="{Binding IsFileAttachmentPresent, Converter={StaticResource VisibleIfTrue}}" IsEnabled="{Binding Path=IsFileAttachmentSelected}"/>
                <Button Content="Save All Files..." Height="20" Margin="10,5,0,0" Name="btnSaveAll" VerticalAlignment="Top" Width="90" Click="btnSaveAll_Click" 
                        Visibility="{Binding IsFileAttachmentPresent, Converter={StaticResource VisibleIfTrue}}" IsEnabled="{Binding Path=IsFileAttachmentPresent}"/>
                <Button Content="Open Email" Height="20" Margin="10,5,0,0" Name="btnOpenEmail" VerticalAlignment="Top" Width="75" Click="btnOpenEmail_Click"
                        Visibility="{Binding IsEmailAttachmentPresent, Converter={StaticResource VisibleIfTrue}}" IsEnabled="{Binding Path=IsEmailAttachmentSelected}"/>
                <Button Content="Close Email" Height="20" Margin="10,5,0,0" Name="btnCloseEmail" VerticalAlignment="Top" Width="75" Click="btnCloseEmail_Click"
                        Visibility="{Binding CanPopMessage, Converter={StaticResource VisibleIfTrue}}" />
            </StackPanel>
            <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
                <RadioButton x:Name="rbContent" Content="Content" Margin="0,10,10,0" IsChecked="True" Click="rbContent_Click"
                              Visibility="{Binding MessagePresent, Converter={StaticResource VisibleIfTrue}}"/>
                <RadioButton x:Name="rbProperties" Content="Properties" Margin="0,10,10,0" Click="rbProperties_Click"
                              Visibility="{Binding MessagePresent, Converter={StaticResource VisibleIfTrue}}"/>
            </StackPanel>
        </Grid>
    </Grid>
</Window>
